﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Prices
{
    class Price
    {
        private event PriceIncreasedEventHandler onPriceIncreased;
        private string name;
        private decimal price;

        bool wasPriceChanged;
        public Price(string name, decimal price)
        {
            if (name == null)
            {
                throw new ArgumentNullException("Parameter name cannot be null.");
            }
            if (price < 0)
            {
                throw new ArgumentException("Price cannot be less than 0.");
            }

            this.name = name;
            this.price = price;
            this.wasPriceChanged = false;
            onPriceIncreased += delegate(object sender, PriceIncreasedArgs args)
            {
                Console.WriteLine("The price has risen.");
                Console.WriteLine("Old price was:{0} and the new price is:{1}.",args.OldValue , args.NewValue);
                wasPriceChanged = true;
            };
        }

        public string Name
        {
            get
            {
                return name;
            }
            set
            {
                name = value;
            }
        }

        public decimal CurrentPrice
        {
            get
            {
                return price;
            }
            set
            {
                wasPriceChanged = false;
                if (value > price)
                {
                    onPriceIncreased(this, new PriceIncreasedArgs(price , value));
                }
                price = value;
            }
        }

        public bool WasPriceChanged
        {
            get
            {
                return wasPriceChanged;
            }
            set
            {
                wasPriceChanged = value;
            }
        }

       
    }
}
